package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.ProcessUserBindMobileBean;
import com.shop2cn.iapi.member.service.ProcessUserBindMobileCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*接收用户绑定手机号消息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ProcessUserBindMobile{
	private static ProcessUserBindMobileBean processuserbindmobileBean;
	private static ProcessUserBindMobileCall processuserbindmobileCall;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("接收用户绑定手机号消息");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		processuserbindmobileBean=new ProcessUserBindMobileBean();
		processuserbindmobileCall=new ProcessUserBindMobileCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(processuserbindmobileCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ProcessUserBindMobile_001() {
		Logger.start(true,"接收用户绑定手机号消息成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			processuserbindmobileBean.setUserId(userId);
			processuserbindmobileBean.setMobile(TestDataManager.getPhoneNum());
			processuserbindmobileBean.setShopId(shopid);
			processuserbindmobileCall.setData(processuserbindmobileBean);
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//手机号加密需要校验
			Logger.verifyEquals(processuserbindmobileBean.getMobile(), GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ProcessUserBindMobile_002() {
		Logger.start(true,"店铺不存在,不处理--现在会自动创建数据");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			processuserbindmobileBean.setUserId(userId);
			processuserbindmobileBean.setMobile(TestDataManager.getPhoneNum());
			processuserbindmobileBean.setShopId(shopid+1);
			processuserbindmobileCall.setData(processuserbindmobileBean);
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//手机号加密需要校验
			//这里的逻辑是收到了通知如果用户不存在 自动创建
			Logger.verifyEquals(processuserbindmobileBean.getMobile(), GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ProcessUserBindMobile_003() {
		Logger.start(true,"用户不存在,不处理");
		try {
			//创建一个新会员
//			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
//			int userId = DGUserCallService.UserCreateCall(usercreateBean);
//			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
//			createMem.setOpenId(usercreateBean.getOpenId());
//			String memid = GodMemberService.creatememberCall(createMem);
			
			processuserbindmobileBean.setUserId(-1);
			processuserbindmobileBean.setMobile(TestDataManager.getPhoneNum());
			processuserbindmobileBean.setShopId(shopid);
			processuserbindmobileCall.setData(processuserbindmobileBean);
			processuserbindmobileCall.callService();			
			Logger.verifyIsContains("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			Logger.verifyIsNull(GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()), "验证不存在");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ProcessUserBindMobile_004() {
		Logger.start(true,"同店铺手机号重复不处理");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			//processuserbindmobileCall 的默认渠道是0 不同渠道还是可以用2个手机号的-h5 app用户打通
			createMem.setAccessSource(0);
			String memid = GodMemberService.creatememberCall(createMem);
			
			processuserbindmobileBean.setUserId(userId);
			processuserbindmobileBean.setMobile(TestDataManager.getPhoneNum());
			processuserbindmobileBean.setShopId(shopid);
			processuserbindmobileCall.setData(processuserbindmobileBean);
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//手机号加密需要校验
			Logger.verifyEquals(processuserbindmobileBean.getMobile(), GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
			
			UserCreateBean usercreateBean2 = DGUserCallService.initUsercreateBean();
			int userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			processuserbindmobileBean.setUserId(userId2);
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//重复手机-不绑定
			Logger.verifyEquals(null, GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ProcessUserBindMobile_005() {
		Logger.start(true,"同店铺用户重复--修改手机号");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			processuserbindmobileBean.setUserId(userId);
			processuserbindmobileBean.setMobile(TestDataManager.getPhoneNum());
			processuserbindmobileBean.setShopId(shopid);
			processuserbindmobileCall.setData(processuserbindmobileBean);
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//手机号加密需要校验
			Logger.verifyEquals(processuserbindmobileBean.getMobile(), GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
			
			processuserbindmobileBean.setMobile(TestDataManager.getPhoneNum());
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//重复手机-不绑定
			Logger.verifyEquals(processuserbindmobileBean.getMobile(), GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//和case 5 重复
	public void Tc_ProcessUserBindMobile_006() {
		Logger.start(true,"接收用户绑定手机号消息成功-已有手机号时修改绑定");
		try {
			processuserbindmobileCall.setData(processuserbindmobileBean);
			processuserbindmobileCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ProcessUserBindMobile_007() {
		Logger.start(true,"会员不存在dguser用户存在,创建会员");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
//			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
//			createMem.setOpenId(usercreateBean.getOpenId());
//			String memid = GodMemberService.creatememberCall(createMem);
			
			processuserbindmobileBean.setUserId(userId);
			processuserbindmobileBean.setMobile(TestDataManager.getPhoneNum());
			processuserbindmobileBean.setShopId(shopid);
			processuserbindmobileCall.setData(processuserbindmobileBean);
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//手机号加密需要校验
			//这里的逻辑是收到了通知如果用户不存在 自动创建
			Logger.verifyEquals(processuserbindmobileBean.getMobile(), GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ProcessUserBindMobile_008() {
		Logger.start(true,"接收用户绑定手机号消息成功-多渠道");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			UserCreateBean usercreateBean2 = DGUserCallService.initUsercreateBean();
			usercreateBean2.setAppSource(DGUserCallService.getAppSourceCode(4));
			int userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			CreateMemberBean createMem2 = GodMemberService.initCreateMemberBean(shopid,userId2,usercreateBean2.getOpenId());
			createMem2.setOpenId(usercreateBean2.getOpenId());
			createMem2.setAccessSource(4);
			String memid2 = GodMemberService.creatememberCall(createMem2);
			
			UserCreateBean usercreateBean3 = DGUserCallService.initUsercreateBean();
			usercreateBean3.setAppSource(DGUserCallService.getAppSourceCode(5));
			int userId3 = DGUserCallService.UserCreateCall(usercreateBean3);
			CreateMemberBean createMem3 = GodMemberService.initCreateMemberBean(shopid,userId3,usercreateBean3.getOpenId());
			createMem3.setOpenId(usercreateBean3.getOpenId());
			createMem3.setAccessSource(5);
			String memid3 = GodMemberService.creatememberCall(createMem3);
			
			processuserbindmobileBean.setUserId(userId);
			processuserbindmobileBean.setMobile(TestDataManager.getPhoneNum());
			processuserbindmobileBean.setShopId(shopid);
			processuserbindmobileCall.setData(processuserbindmobileBean);
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//手机号加密需要校验
			Logger.verifyEquals(processuserbindmobileBean.getMobile(), GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
			
			
			processuserbindmobileBean.setUserId(userId2);
			processuserbindmobileBean.setAccessSource("4");
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//手机号加密需要校验
			Logger.verifyEquals(processuserbindmobileBean.getMobile(), GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
			
			processuserbindmobileBean.setUserId(userId3);
			processuserbindmobileBean.setAccessSource("5");
			processuserbindmobileCall.callService();			
			Logger.verifyEquals("ok", processuserbindmobileCall.getReturnData(), "验证返回");
			//手机号加密需要校验
			Logger.verifyEquals(processuserbindmobileBean.getMobile(), GodMemberService.briefmemberinfoCall(processuserbindmobileBean.getShopId(), processuserbindmobileBean.getUserId()).getMobile(), "验证mobile");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}